# 定义购物车页面元素
# 定义对象库层
import time

from selenium.webdriver.common.by import By

from base.tmp.base import base_tmp, bases_tmp


class bash(base_tmp):
    def __init__(self):
        super().__init__()

        # 首页元素
        self.sy = By.XPATH, '/html/body/div[2]/div/div[3]/ul/li[1]/a'

        # 账户元素
        self.user = By.XPATH, '//*[@id="ng-app"]/body/div[1]/div/ul[1]/div/a[1]'

        # 商品元素
        self.toop = By.XPATH, '/html/body/div[4]/div[2]/div[2]/a[1]/div[3]/img'

        # 加入购物车元素
        self.jr = By.XPATH, '//*[@id="join_cart"]'

        # 关闭弹窗元素
        self.gb = By.XPATH, '//*[@class="layui-layer layui-anim layui-layer-iframe layui-layer-rim"]/span'

        # 购物车元素
        self.guc = By.XPATH, '//*[@id="hd-my-cart"]/a/div'

        # 删除元素
        self.dele = By.XPATH, '//*[@id="removeGoods"]'

    # 定位首页元素
    def get_sy(self):
        return  self.get_element(self.sy)

    # 定位账户元素
    def get_user(self):
        return self.get_element(self.user)

    # 定位商品元素
    def get_toop(self):
        return self.get_element(self.toop)

    # 定位加入购物车元素
    def get_jr(self):
        return self.get_element(self.jr)

    # 定位关闭弹窗元素clic
    def get_gb(self):
        return self.get_element(self.gb)

    # 定位购物车元素
    def get_guc(self):
        return self.get_element(self.guc)

    # 定位删除元素
    def get_dele(self):
        return self.get_element(self.dele)

# 定义操作层
class bash_imp(bases_tmp):
    def __init__(self):
        super().__init__()
        self.login = bash()

    # 点击首页
    def click_sy(self):
        return self.login.get_sy().click()

    # 获取账户信息
    def click_user(self):
        return self.login.get_user().text

    # 点击商品
    def click_toop(self):
        return self.login.get_toop().click()

    # 加入购物车
    def click_jr(self):
        return self.login.get_jr().click()

    # 关闭弹窗
    def click_gb(self):
        return self.login.get_gb().click()

    # 点击购物车
    def click_guc(self):
        return self.login.get_guc().click()

    # 点击删除
    def click_dele(self):
        return self.login.get_dele().click()


# 定义业务层
class bash_sta:
    def __init__(self):
        self.login = bash_imp()

    # 账户信息
    def user(self):
        time.sleep(3)
        return self.login.click_user()

    # 购物车操作
    def start(self):
        self.login.click_sy()
        time.sleep(2)
        self.login.click_toop()
        time.sleep(1)
        self.login.click_jr()
        time.sleep(1)
        self.login.click_gb()
        time.sleep(1)
        self.login.click_guc()
        time.sleep(1)
        self.login.click_dele()